<?php session_start(); ?>

<?php

    if(isset($_GET['del']))
    {
        include "Datasource.php";
        include "Ticket.php";
        include "TicketDao.php";
        include "CustContactLog.php";
        include "CustContactLogDao.php";
        include "WorkDone.php";
        include "WorkDoneDao.php";
        include "CustomerProduct.php";
        include "CustomerProductDao.php";

        $conn = new Datasource("localhost","theanykey","root","");
        $ticket = new Ticket();
        $ticketDao = new TicketDao();
        $ticketID = $_GET['ticketID'];
        $ticket->setTicketID($ticketID);

        $workDone = new WorkDone();
        $workDone->setTicketID($ticketID);
        $workDoneDao = new WorkDoneDao();

        $custContact = new CustContactLog();
        $custContact->setTicketID($ticketID);
        $custContactDao = new CustContactLogDao();

        $custProduct = new CustomerProduct();
        $custProduct->setTicketID($ticketID);
        $custProductDao = new CustomerProductDao();

        //delete work dones
        $workDoneResults = $workDoneDao->searchMatching($conn, $workDone);
        
        foreach ($workDoneResults as $currWork)
        {
            $workDoneDao->delete($conn, $currWork);
        }
        //delete contact logs
        $custContactResults = $custContactDao->searchMatching($conn, $custContact);
        foreach ($custContactResults as $currContact)
        {
            $custContactDao->delete($conn, $currContact);
        }
        //delete customer product
        $custProductResults = $custProductDao->searchMatching($conn, $custProduct);

        foreach ($custProductResults as $currProduct)
        {
            $custProductDao->delete($conn, $currProduct);
        }


        //delete ticket
        $ticketDao->delete($conn, $ticket);







    }

?>



<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <LINK REL=StyleSheet HREF="maintenancePagesCSS.css" TYPE="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body <?php if(isset($_GET['del'])){ print(" onload='closeRefresh();'");}  ?>>

        <center>
        <form action='TicketDelete.php?ticketID=<?php print($_GET['ticketID']);?>&del=true' method='post'>
            <p>Are you sure you want to delete this Ticket entry?</p>
            <input type='submit' value="Delete">
            <input type="button" value="Cancel" onclick="window.close();">

        </form>
        </center>


    </body>

    <script type="text/javascript">
        function closeRefresh()
        {
            
            window.opener.location.href = window.opener.location.href;
            window.close();

         }


    </script>
</html>